package org.lwd.datalink.service.impl;

import org.lwd.datalink.domain.sys.SysPropertiesInfo;
import org.lwd.datalink.mapper.SysPropertiesMapper;
import org.lwd.datalink.service.SysPropertiesService;
import org.lwd.datalink.utils.ValidatorUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 系统参数
 *
 * @Author: weidong.lin
 * @Date: create in 2024/4/2 14:03
 */
@Service
public class SysPropertiesServiceImpl implements SysPropertiesService {

    @Resource
    private SysPropertiesMapper sysPropertiesMapper;

    @Override
    public Map<String, String> map() {
        List<SysPropertiesInfo> list = sysPropertiesMapper.findSysPropertieList();
        if (ValidatorUtil.isNotEmpty(list)) {
            return list.stream().collect(Collectors.toMap(SysPropertiesInfo::getPropertiesKey, SysPropertiesInfo::getPropertiesValue));
        } else {
            return new HashMap<String, String>();
        }
    }

    @Override
    public SysPropertiesInfo getSysPropertiesByKey(String key) {
        SysPropertiesInfo sysPropertiesInfo = sysPropertiesMapper.getSysPropertiesByKey(key);
        return sysPropertiesInfo;
    }
}
